import com.sun.tools.attach.VirtualMachine

fun main() {
    VirtualMachine.list().forEach {
        val displayName = it.displayName()
        println("attaching $displayName")
        if (!displayName.endsWith("server-1.0-SNAPSHOT.jar")) {
            return@forEach
        }
        val attach = VirtualMachine.attach(it.id())
        println("attaching $displayName")
        attach.loadAgent("/home/yanwei/IdeaProjects/java-agent/agent/target/agent-1.0-SNAPSHOT.jar", "/tmp/classes")
    }
}